package com.jx.web;

import com.jx.common.Result;
import com.jx.dto.GoodDetailDto;
import com.jx.pojo.Good;
import com.jx.service.DetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@RequestMapping("/detail")
public class DetailController {
    @Autowired
    private DetailService detailService;

    @RequestMapping("/{id}")
    public Result<GoodDetailDto> getGoodDetailById(@PathVariable("id") int id) {
        Result<GoodDetailDto> res = new Result<>();
        // 根据商品id查询商品详细信息
        GoodDetailDto goodDetailDto = detailService.getGoodDetailById(id);
        // 封装结果集
        res.setCode(200);
        res.setMessage("成功");
        res.setData(Arrays.asList(goodDetailDto));
        return res;
    }
}
